'use strict';

/* Controllers */
// signin controller
app.controller('SigninFormController', ['$rootScope', '$scope', '$state', '$cookieStore','AccountService', function ($rootScope, $scope, $state,$cookieStore, accountService) {
    $scope.codeurl = accountService.getValidImgCode();
    $scope.login = function () {
        $scope.errInfo = null;
        accountService.login($scope.user).then(function (response) {
            if (response.code == 0) {
                $rootScope._useraccount = response.data;
                $cookieStore.put('_login',1,{'expires': -1});
                $state.go("app.home");
            } else {
                $scope.errInfo = response.message;
                $scope.codeurl = accountService.getValidImgCode();//刷新验证码
            }
        }, function (fail) {
            //服务器出错,非200code

        });
    };
    $scope.refreshCaptcha = function () {
        $scope.codeurl = accountService.getValidImgCode();
    }

}])
;